<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            margin: 100px auto;
            position: relative;
        }

        .block input {
            height: 30px;
            margin-bottom: 20px;
            width: 200px;
            box-sizing: border-box;
            border: 2px solid gray;
            border-radius: 8px;
            outline: 0;
            /* flex: 1; */
        }

        span {
            color: blue;
            font-size: 12px;
            display: block;
            position: absolute;
            right: 0px;
        }

        .anniu {
            background-color: blue;
            color: white;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="block">
            <input type="text" placeholder="手机号/用户名/邮箱">
        </div>
        <div class="block">
            <input type="password" placeholder="密码">
        </div>
        <span>忘记密码</span>
        <br>
        <div class="block">
            <input type="button" value="登录" class="anniu">
        </div>
    </div>
</body>

</html>
<script src="./封装ajax .js"></script>
<script>
    var inputs = document.querySelectorAll('.block input')
    console.log(inputs);
    inputs[2].onclick = function () {
        if (inputs[0].value && inputs[1].value) {
            // if (/^1[3-9]\d{9}$/.test(inputs[0].value) || /^\w{1,}@[0-9a-z]{1,}\.(com|cn|org)$/.test(inputs[1].value)) {
                if(/^\d{4}$/.test(inputs[1].value)){
                ajax('get', 'https://yantianfeng.com/api/login', { username: inputs[0].value, password: inputs[1].value }, function (data) {
                    if (data.status == 200) {
                        alert('登陆成功')
                    }
                    else {
                        alert('登录失败')
                    }
                })
            }
            else {
                alert('手机号/用户名/邮箱不正确')
            }
        }
        else {
            alert('手机号/用户名/邮箱不能为空')
        }
    }
</script>